Page 1 of 2
關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 3:00 pm
by 韋信
http://www.on099.com/viewtopic.php?p=2528#p2528" onclick="window.open(this.href);return false;
為解決 link 返 phpbb upload 既相,例如
http://www.on099.com/download/file.php?id=4" onclick="window.open(this.href);return false;
用唔到 [light] (fancybox) 功能。現時 BBCode 背後既 script 係:
Code: Select all
<a class="fancybox" rel="fancybox-button" href="{URL}"><img src="{URL}" alt="" /></a>
可唔可以寫個 javascript detect {URL} 最後一個字係咪數字,唔係就跟上面既 code,係就用下面:
Code: Select all
<a class="fancybox" rel="fancybox-button" href="{URL}.jpg"><img src="{URL}" alt="" /></a>
P.S. 細佬咁多年黎無寫過 javascript.

Re: 關乎 on099 福祉:求救 javascript 高手
Posted: Tue Nov 04, 2014 3:01 pm
by alexchrome
Re: 關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 3:09 pm
by poelam
assume url is the string
var pos = url.search("file.php");
if(pos>=0)
{
//add .jpg
}
else
{
//no .jpg needed
}
something like this?
Re: 關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 3:16 pm
by 韋信
poelam wrote:
assume url is the string
var pos = url.search("file.php");
if(pos>=0)
{
//add .jpg
}
else
{
//no .jpg needed
}
something like this?
類似 {URL} 係 string
Re: 關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 3:26 pm
by wmmokk
Code: Select all
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
// add .jpg
} else {
// no need to add
}
Re: 關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 3:41 pm
by 韋信
wmmokk wrote:
Code: Select all
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
// add .jpg
} else {
// no need to add
}
呢個係 view source code 出黎既樣,好似唔係好得
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
}
</script>
Re: 關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 3:51 pm
by wmmokk
韋信 wrote:
wmmokk wrote:
Code: Select all
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
// add .jpg
} else {
// no need to add
}
呢個係 view source code 出黎既樣,好似唔係好得
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
}
</script>
Where is ""
http://on099.com/download/file.php?avat ... 994888.jpg" come from? (is it the url variable?)
If the url variable have http:// then the regexURL should be
Code: Select all
var regexURL = /^(?:(?:http:\/\/)?(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
Re: 關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 4:02 pm
by 韋信
wmmokk wrote:
韋信 wrote:
wmmokk wrote:
Code: Select all
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
// add .jpg
} else {
// no need to add
}
呢個係 view source code 出黎既樣,好似唔係好得
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
}
</script>
Where is ""
http://on099.com/download/file.php?avat ... 994888.jpg" come from? (is it the url variable?)
If the url variable have http:// then the regexURL should be
Code: Select all
var regexURL = /^(?:(?:http:\/\/)?(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
}
This is refering to :
http://www.on099.com/viewtopic.php?p=2544#p2544" onclick="window.open(this.href);return false;
When I apply this code to BBCode setting:
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}\"><img src=\"{URL}\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}.jpg\"><img src=\"{URL}\" alt=\"\" /></a>";
}
</script>
It did not work on your previous post.
Re: 關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 4:11 pm
by wmmokk
韋信 wrote:
wmmokk wrote:
韋信 wrote:
wmmokk wrote:
Code: Select all
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
// add .jpg
} else {
// no need to add
}
呢個係 view source code 出黎既樣,好似唔係好得
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
}
</script>
Where is ""
http://on099.com/download/file.php?avat ... 994888.jpg" come from? (is it the url variable?)
If the url variable have http:// then the regexURL should be
Code: Select all
var regexURL = /^(?:(?:http:\/\/)?(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
}
This is refering to :
http://www.on099.com/viewtopic.php?p=2544#p2544" onclick="window.open(this.href);return false;
When I apply this code to BBCode setting:
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}\"><img src=\"{URL}\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}.jpg\"><img src=\"{URL}\" alt=\"\" /></a>";
}
</script>
It did not work on your previous post.
I have not use BBCode before but I guess you can write code as :
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var url = "{URL}";
var regexURL = /^(?:(?:http:\/\/)?(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}\"><img src=\"{URL}\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}.jpg\"><img src=\"{URL}\" alt=\"\" /></a>";
}
</script>
Re: 關乎 on099 福祉:求教 javascript 高手
Posted: Tue Nov 04, 2014 4:21 pm
by 韋信
wmmokk wrote:
韋信 wrote:
wmmokk wrote:
韋信 wrote:
wmmokk wrote:
Code: Select all
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
// add .jpg
} else {
// no need to add
}
呢個係 view source code 出黎既樣,好似唔係好得
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\"><img src=\"http://on099.com/download/file.php?avatar=114_1414994888.jpg\" alt=\"\" /></a>";
}
</script>
Where is ""
http://on099.com/download/file.php?avat ... 994888.jpg" come from? (is it the url variable?)
If the url variable have http:// then the regexURL should be
Code: Select all
var regexURL = /^(?:(?:http:\/\/)?(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
}
This is refering to :
http://www.on099.com/viewtopic.php?p=2544#p2544" onclick="window.open(this.href);return false;
When I apply this code to BBCode setting:
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var regexURL = /^(?:(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}\"><img src=\"{URL}\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}.jpg\"><img src=\"{URL}\" alt=\"\" /></a>";
}
</script>
It did not work on your previous post.
I have not use BBCode before but I guess you can write code as :
Code: Select all
<p id="inner"></p>
<script type="text/javascript">
var url = "{URL}";
var regexURL = /^(?:(?:http:\/\/)?(?:www\.)?on099\.com\/download\/)?file\.php\?id=([0-9]+)/i;
if (url.test(regexURL)) {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}\"><img src=\"{URL}\" alt=\"\" /></a>";
} else {
document.getElementById('inner').innerHTML = "<a class=\"fancybox\" rel=\"fancybox-button\" href=\"{URL}.jpg\"><img src=\"{URL}\" alt=\"\" /></a>";
}
</script>
唔得 ..... 我諗諗其他辦法。