开发者

Parse variable from URL to display different content on HTML page (JS)

开发者 https://www.devze.com 2023-01-31 06:30 出处:网络
I have an email newsletter being sent out each week with a different subject and there\'s one webpage where you can click to from the email.

I have an email newsletter being sent out each week with a different subject and there's one webpage where you can click to from the email.

On week 1 the email is about 'phones' and if someone clicked the link it could contain a slightly different variable (for example week 1 being ?content=phone on the end of the URL).

When the webpage loads, only the content on phones is displayed.

There is going to be 8 emails so there will be 8 sets of content and different variables in the URLs on each week.

开发者_如何学编程

I just need a javascript to do this?


If this has to be done on a static page on client side, you could use window.location.hash to show/hide different parts of the page.

https://developer.mozilla.org/en/window.location


You can do something very simple and old-school with just HTML like:

<a name="phone"></a><h1>This is my phone section</h1>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<a name="car"></a><h1>This is my car section</h1>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<a name="house"></a><h1>This is my house section</h1>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>

Then all of your urls look like: emaillink1.html#car

Where the section you want at the top follows the hash mark.

0

精彩评论

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