开发者

Linking to a page to also load javascript

开发者 https://www.devze.com 2023-03-09 14:01 出处:网络
I want to be able to create a link to a specific page on my site and then also have that link load a specific piece of javascript on that page.

I want to be able to create a link to a specific page on my site and then also have that link load a specific piece of javascript on that page.

For example:

I link to this page:

http://www.myexample.com/cat/test.html

Then I want the link to also open a topic on arrival by executing a piece of javascript:

javascript:showContentDesc(59, 11, 'left'), scroll(0,120)

I have done some research and I believe I have to do the following:

1- Modify the URL 开发者_如何学Pythonto specify the DIV to open 2- Have an onLoad handler that parses the URL and opens the appropriate DIV.

So I will then have a URL like this:

http://www.myexample.com/cat/test.html#1

The link will take me toe the page where an onLoad Handler will parse the URL and then call the

javascript:showContentDesc(59, 11, 'left'), scroll(0,120)  piece of script.

If the URL were

http://www.myexample.com/cat/test.html#2

it would then be parsed by the online handler and run a different piece of javascript

javascript:showContentDesc(60, 11, 'left'), scroll(0,120)

So my question is, based on this being correct:

1 - What do I need to do to create the onLoad Handler? 2 - How do I make the script that parses the url and then runs the the appropriate piece of javascript?

I hope this is understandable.

Thanks for the help as always!


OK so this is what I have figured out thus far...

In my joomla module (The one I want to be able to load a spesific topic of has this piece of code on the bottom.

<script type="text/javascript">
showContentDesc("<?php echo $module->id; ?>",0,"<?php echo $menuPositions; ?>");
</script>

This tells the browser to load topic 0 - this can be changed to 2 or what ever I want.

So I believe all I have to do now is add a handler that parses the URL somewhere and then have the 0 in the code be the value of the part the handler parses ??

Any help???


This made it work!

 <script type="text/javascript">
showContentDesc("<?php echo $module->id; ?>"<?php $page=$_GET['page'];

if(isset($_GET['page']))
echo  "$page";
else
echo "0";
?>"<?php echo $menuPositions; ?>");
</script>
0

精彩评论

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