joethemovie joethemovie - 2 months ago 14
HTML Question

Targeting URL content and displaying on page

I'm working with a client who's stuck using a widget based website and needs a custom built web app. We're hosting it off site. I need to pull product information from their main site to populate the off site page.

I wrote this to pull H1 content from their main site, this will serve as the link to the off site page.

<a href="#" id="specialURL">BUILD LEASE</a>

<script type="text/javascript">
$(document).ready(function() {

var url = $('h1').html();
url = url.replace(/\s+/g, '-').toLowerCase()+'.html';

$('#specialURL').attr('href', '' + url );


Now I need to turn the URL content back into an h1 on the off site page.

Also, if possible, does anyone know how I could store price information in the URL?

Such as

Then, same as the H1, display on the off site page.



Anything you're sticking in a url should be uri encoded. this will take care of spaces too so the regex isn't necessary..

$('#specialURL').attr('href', '' + encodeURIComponent(url) +"&price=" + encodeURIComponent("about tree fiddy"));

Then you can get that junk from the url using the server (php's $_GET for example), or you can use the function here to get those parameters with javascript..