關乎 on099 福祉:求教 javascript 高手

歡迎開開心心齊吹水
User avatar
韋信
Posts: 1960
Joined: Thu Oct 23, 2014 10:54 pm
Location: 唔比著黃衫踢波既球場
Contact:

關乎 on099 福祉:求教 javascript 高手

Post 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. :onion16:
Last edited by 韋信 on Tue Nov 04, 2014 3:05 pm, edited 1 time in total.
User avatar
alexchrome
Posts: 1636
Joined: Tue Oct 28, 2014 3:56 pm

Re: 關乎 on099 福祉:求救 javascript 高手

Post by alexchrome »

**== **== **== **== **== **== **== **== **==
Image
User avatar
poelam
Posts: 35
Joined: Thu Oct 30, 2014 9:52 pm

Re: 關乎 on099 福祉:求教 javascript 高手

Post 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?
User avatar
韋信
Posts: 1960
Joined: Thu Oct 23, 2014 10:54 pm
Location: 唔比著黃衫踢波既球場
Contact:

Re: 關乎 on099 福祉:求教 javascript 高手

Post 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
User avatar
wmmokk
Posts: 780
Joined: Wed Oct 29, 2014 4:04 pm

Re: 關乎 on099 福祉:求教 javascript 高手

Post 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
}

User avatar
韋信
Posts: 1960
Joined: Thu Oct 23, 2014 10:54 pm
Location: 唔比著黃衫踢波既球場
Contact:

Re: 關乎 on099 福祉:求教 javascript 高手

Post 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>
User avatar
wmmokk
Posts: 780
Joined: Wed Oct 29, 2014 4:04 pm

Re: 關乎 on099 福祉:求教 javascript 高手

Post 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;
User avatar
韋信
Posts: 1960
Joined: Thu Oct 23, 2014 10:54 pm
Location: 唔比著黃衫踢波既球場
Contact:

Re: 關乎 on099 福祉:求教 javascript 高手

Post 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.
User avatar
wmmokk
Posts: 780
Joined: Wed Oct 29, 2014 4:04 pm

Re: 關乎 on099 福祉:求教 javascript 高手

Post 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>
User avatar
韋信
Posts: 1960
Joined: Thu Oct 23, 2014 10:54 pm
Location: 唔比著黃衫踢波既球場
Contact:

Re: 關乎 on099 福祉:求教 javascript 高手

Post 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>
唔得 ..... 我諗諗其他辦法。
Post Reply