简体   繁体   中英

Make javascript run on external link click?

Ok, lets say I have page.php. If i'm currently viewing page.php and I click this link:

<a href="#?call=friend.request&amp;user_id=10&amp;width=420&amp;height=250">Link</a>

The javascript box will pop up. Success!

However, if I'm on a different page, and I link to

<a href="http://domain.com/page.php#?call=friend.request&amp;user_id=10&amp;width=420&amp;height=250">Link</a>

The javascript box will not pop up when the page loads.

Any ideas?

I can't edit or find the javascript code that executes the said function, unfortunately.

That's not the idea of JS, so basically what you have to do is a check in the window.onload event, so you can check the window.location to search for the # string and then parse whatever you want.

As I said, that's not the general idea of JS, so it turn out to be a little messy.

您将必须在页面加载时运行一个函数,该函数将检查window.location.search(可访问?call = ....部分),然后调用与page.php上的链接所调用的相同的javascript。

My guess is that linking to the page directly like that, it sees the ? code as part of the querystring and not the hash thus making the hash value just an empty # . Can you do this without the ? in the hash value? Or you can try URL encoding it using %3F .

<a href="http://domain.com/page.php#%3Fcall=friend.request&amp;user_id=10&amp;width=420&amp;height=250">Link</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM