开发者

Make javascript run on external link click?

开发者 https://www.devze.com 2022-12-15 22:08 出处:网络
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>

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;开发者_StackOverflow社区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.


You would have to run a function on page load which would inspect window.location.search (which provides access to the ?call=.... part) And then calls the same javascript that the links on your page.php are calling.


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消