Trigger a script to run again?

Please post all questions and comments regarding Help & Manual 7 here.

Moderators: Alexander Halser, Tim Green

Post Reply
Mark Wilsdorf
Posts: 151
Joined: Thu Dec 24, 2009 8:41 pm
Contact:

Trigger a script to run again?

Unread post by Mark Wilsdorf »

I'm so close to getting everything I want...

I'm using H&M 7.1 and a Premium Pack 3.15 skin.

In some topics I insert HTML like the following, which displays a formatted button including the item's current price, etc., from our shopping cart system:

<p style="text-align: center;"><a href="https://goflagship.dpdcart.com/cart/add ... _id=138569..[TRUNCATED HERE]..data-text="Buy Now" data-variant="price-right" data-dpd-type="button">Buy Now</a></p><script src="https://goflagship.dpdcart.com/dpd.js"></script>

When the WebHelp page is displayed this inserted HTML results in a button that looks like this:
BuyNowPrice.png
...exactly what I want. But if I click on an entry in the Keyword Index panel (toggles may open, and the page scrolls to the indexed location) then those button links lose their formatting. The button above ends up displayed like this:
BuyNowNoFmt.png
Any ideas on how to remedy this?
You do not have the required permissions to view the files attached to this post.
User avatar
Alexander Halser
EC-Software Support
Posts: 4098
Joined: Mon Jun 24, 2002 7:24 pm
Location: Salzburg, Austria
Contact:

Re: Trigger a script to run again?

Unread post by Alexander Halser »

Hi Mark,

This is not enough information to even make a guess. Where does the CSS style of your button come from? Is it inline CSS or is it an external style sheet?

I recommend to use the browser tools (F12) to watch what happens at runtime. Check for javascript errors and inspect the button element which CSS the browser applies to it. Do this in both cases, the regular page load and with the keywords highlighted.
Alexander Halser
Senior Software Architect, EC Software GmbH
Mark Wilsdorf
Posts: 151
Joined: Thu Dec 24, 2009 8:41 pm
Contact:

Re: Trigger a script to run again?

Unread post by Mark Wilsdorf »

I'm not making any headway.

If I use the Inspector pane of the browser tools, here's the code for the button when it is displaying properly. Apparently the dpd.js Javascript creates this html from the source data (shown in the 2nd image, below) when the page is first loaded.
BuyNowHTML1.png
And here's the code for the button after clicking on an entry in the Index pane, which causes the button to display as a plain link. The code has reverted to the original source code for the button.
BuyNowHTML2.png
If you have time to take a look, here's where the page is located: http://www.goflagship.com/books/index.html

Thanks,
Mark Wilsdorf
You do not have the required permissions to view the files attached to this post.
Mark Wilsdorf
Posts: 151
Joined: Thu Dec 24, 2009 8:41 pm
Contact:

Re: Trigger a script to run again?

Unread post by Mark Wilsdorf »

Oh, I also meant to add...

The CSS is dynamically generated, inline, by the call to dpd.js (I think. Sorry, I'm not much of a Web programmer). The second graphic shows what the original source code looks like; i.e., the HTML code I inserted in H&M.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: Trigger a script to run again?

Unread post by Simon Dismore »

Two quick thoughts:
  • Try publishing without a skin. If that works perhaps you need to make an explicit call to the dpd cart code when PP3.15 loads the topic from the keyword index.
  • Try copying the dpd.js code to your own server (and changing the src= accordingly). If that works perhaps you are having a cross-original problem, though I don't see why that should happen only with a link from the keyword index and not from the main title.
Mark Wilsdorf
Posts: 151
Joined: Thu Dec 24, 2009 8:41 pm
Contact:

Re: Trigger a script to run again?

Unread post by Mark Wilsdorf »

Thanks Simon.

> ... when PP3.15 loads the topic from the keyword index.

Can you tell me how to get ahold of that event, to make the call.
Simon Dismore
Posts: 454
Joined: Thu Nov 16, 2006 1:29 pm
Location: London, UK

Re: Trigger a script to run again?

Unread post by Simon Dismore »

Mark Wilsdorf wrote:Can you tell me how to get ahold of [when PP3.15 loads the topic from the keyword index]
I've no idea, I'm afraid. I was simply guessing at tests that might narrow down the problem. If it turns out your dpd buttons are always styled correctly in conventional WebHelp, but not always in WebHelp3, that's something Tim might help with. Likewise if you get different results depending on whether the script is hosted locally with HTTP vs remotely via HTTPS, that might be a clue. I know some cross-domain actions can fail silently without console messages.
Mark Wilsdorf
Posts: 151
Joined: Thu Dec 24, 2009 8:41 pm
Contact:

Re: Trigger a script to run again?

Unread post by Mark Wilsdorf »

Thanks for your help. I'll hope Tim can reply when he gets back.
User avatar
Tim Green
Site Admin
Posts: 23156
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Trigger a script to run again?

Unread post by Tim Green »

Hi Mark,

I think what the problem you're probably running into here is the new dynamic nature of the WebHelp 3 format. As Alexander has already indicated, what is important here is where you are putting your code. If it is not in your topic it will not be there when a topic is loaded while the user is browsing.

This is because there are two copies of every topic: The pre-rendered HTML version which is stored normally in the HTML topic file, and a compressed JavaScript version which only contains the topic content. The full version is the normal HTML file that is opened when you first visit a topic via a URL. Once the page is displayed, all the other topics the user displays are loaded into the page dynamically from the compressed JavaScript versions of the topic content stored in the /jstopics folder.

With the exception of the predefined footer, which is handled in a special way, anything you add to the main template will not be reproduced in topics while the user is browsing. This is because a new topic is loaded not by reloading the template, but by replacing the topic content in the page with the raw topic content from the JavaScript version, which contains only the compressed HTML content from your topic.
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
Mark Wilsdorf
Posts: 151
Joined: Thu Dec 24, 2009 8:41 pm
Contact:

Re: Trigger a script to run again?

Unread post by Mark Wilsdorf »

OK, it's been years since I first posted this but I'd like to revive the thread at least briefly. Before, I was facing a deadline and dropped this thread, and went with static images for buttons.

Now I'm building a Web site with H&M again and using the DPD (GetDPD.com) shopping cart system again. DPD allows configuring Add to Cart buttons which are rendered dynamically and can include current price information for the product being purchased. The benefit is that price information can be updated in the product database, then every Add to Cart button throughout the site is automatically updated with current price information.

I have a basic understanding of Tim's last post on this topic. I get that the pre-rendered HTML gets displayed first when browsing, and that's why a dynamically rendered button would display as plain text.

Here's what a test page looks like when it first loads. The first button is static. The next two are dynamic, and displayed as text initially:
image1.jpg
If I click on either the 2nd or 3rd link ("button"), upon returning from a Shopping Cart page both buttons are fully rendered:
image2.jpg
Here's a (somewhat shortened) example of the code for the 2nd button:

Code: Select all

<a data-dpd-type="button" data-text="Add to Cart" data-bg-color="fdb731" 
data-bg-color-hover="ffd441" data-text-color="586064" 
href="https://mcreekag.dpdcart.com/cart/add?product_id=219559&amp;method_id=239316">
Add to Cart</a>
<script src="https://mcreekag.dpdcart.com/dpd.js"></script>
What I don't understand:

(1) How DPD's Javascript gets called for rendering both the 2nd & 3rd buttons after either of them is clicked. Is it just that after clicking one of them DPD's Javascript is loaded and therefore locally available for rendering the page?

(2) Tim commented "...what is important here is where you are putting your code. If it is not in your topic it will not be there when a topic is loaded while the user is browsing."

However this is not my code but DPD's so I can't include it directly in my HTML. So, related to (1) above, is there any way to trigger loading it and rendering the dynamic buttons when a page first loads? (I realize this may sound silly given that you've told me that a pre-rendered HTML page gets loaded first, but I'm hoping there is something I've missed.)
You do not have the required permissions to view the files attached to this post.
User avatar
Tim Green
Site Admin
Posts: 23156
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Trigger a script to run again?

Unread post by Tim Green »

Hi Mark,
However this is not my code but DPD's so I can't include it directly in my HTML. So, related to (1) above, is there any way to trigger loading it and rendering the dynamic buttons when a page first loads? (I realize this may sound silly given that you've told me that a pre-rendered HTML page gets loaded first, but I'm hoping there is something I've missed.)
I'd have to have a look at the shop system to see if and how it can be integrated in a dynamic skin, which would probably be a few hours or even a couple of days work. :?

However, offhand I would tend to recommend against trying to put something like this into your documentation. Instead, put it in its own shop page on your web server and link to it. That would be much more reliable and trouble-free. You Could have product links and even buttons in your topic pages, but those would be regular buttons that you insert in each topic, that then link to your shop page.
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
User avatar
Tim Green
Site Admin
Posts: 23156
Joined: Mon Jun 24, 2002 9:11 am
Location: Bruehl, Germany
Contact:

Re: Trigger a script to run again?

Unread post by Tim Green »

Hi Mark,
However this is not my code but DPD's so I can't include it directly in my HTML. So, related to (1) above, is there any way to trigger loading it and rendering the dynamic buttons when a page first loads? (I realize this may sound silly given that you've told me that a pre-rendered HTML page gets loaded first, but I'm hoping there is something I've missed.)
I'd have to have a look at the shop system to see if and how it can be integrated in a dynamic skin, which would probably be a few hours or even a couple of days work. :?

However, offhand I would tend to recommend against trying to put something like this into your documentation. Instead, put it in its own shop page on your web server and link to it. That would be much more reliable and trouble-free. You Could have product links and even buttons in your topic pages, but those would be regular buttons that you insert in each topic, that then link to your shop page.
Regards,
Tim (EC Software Documentation & User Support)

Private support:
Please do not email or PM me with private support requests -- post to the forum directly.
Mark Wilsdorf
Posts: 151
Joined: Thu Dec 24, 2009 8:41 pm
Contact:

Re: Trigger a script to run again?

Unread post by Mark Wilsdorf »

> Instead, put it in its own shop page on your web server and link to it.

I think I get what you are saying, but that would seem to defeat the value of the dynamic nature of button text updating. Each time a button is rendered it displays the product's current price on the button. If the price changed two days ago, a customer visiting the site would see a new price on the button.

If it were possible to put all dynamic buttons on a separate page as you suggest, I can't see how that would work, as DPD's script file would still need to be dynamically loaded somehow--otherwise the button rendering would be the same as now. And copying DPD's Javascript into a <script> element on that page would be a terrible kludge...because if the Javascript changes on DPD's server I'd have to manually update the page. The potential for precipitating a terrible experience--like Add to Cart buttons which suddenly stopped working--might be significant.

If I go with static image buttons I'll have to put price information in nearby accompanying text, and remember to update that text if the product's price gets changed in the shopping cart database. Not a big deal I guess; I've never had the luxury of dynamically updated price information displayed on a Web site without writing any code, but it would have been nice. I'll just go back to "the old way"; I know how to make that work. :D

Anyway, thanks for your comments Tim.
Post Reply