任何人都可以帮我解决这个问题吗?我是编程新手,现在我遇到了这个问题。 我在最终生成的PDF中有超链接(从RTF转换为PDF)。当我尝试单击PDF中的链接时,它们在同一个iframe窗口中打开,而不是打开新窗口。
我希望在新窗口中打开我的超链接每当用户点击链接时。我正在使用最新版本的Aspose PDF。我尝试使用以下代码。
/*
causes a promise returning function not to be called
untill less than max are active
usage example:
max2 = throttle(2);
functions = [fn1,fn2,fn3...fn100];//functions returning promise
params = [param1,param2,param3...param100]
Promise.all(//even though a 100 promises are created, only 2 are active
functions.map(
(fn,index)=>
max2(fn)(params[index])
.then(...)
)
)
*/
const throttle =
(max) =>{
var que = [];
var running = 0;
const wait = function*(resolve,fn,arg){
return resolve(fn(arg));
};
const nextInQue = ()=>{
const it = que[0];
que=que.slice(1);
if(it){
it.next();
}
return true;
};
const queItem = (fn,arg)=>
new Promise(
(resolve,reject)=>que.push(wait(resolve,fn,arg))
)
;
return (fn)=>(arg)=>{
const p = queItem(fn,arg)
.then(x=>nextInQue() && x)
;
running++;
if(running<=max){
nextInQue();
}
return p;
};
}
;
/*
result.toPromse(result)
if result is type Error a rejected promise is returned
reject reason is result.val
if result is of type Value a resolved promise is returned
resolve is result.val
else a resolved promise is returned
resolve value is result
result toResult
if promise is rejected the rejection is caught
the promise resolves to a result of type Error
with val of reject reason
if promise is resolved
the promise resolves to a result of type Value
with val of resolved value
*/
const result = (function(){
const Error = function(val){this.val=val;}
const Value = function(val){this.val=val;}
return {
toResult:promise =>
promise.then(
val => new Value(val)
,reject => new Error(reject)
)
//a promise resolving in a result (Error or Value)
,toPromise:result =>
result.then(
x =>
(x.constructor === Error)
?Promise.reject(x.val)
:(x.constructor === Value)
?Promise.resolve(x.val)
:Promise.resolve(x)
)
}
})();
const test = function *() {
var i = -1;
//maximal 2 unresolved promises
const max2 = throttle(2);
const paginatedResources = [
'/index.html',
//causes fetch to return a rejected promise
'http://ldsjdslfjalksfljasdflkjasdflkjsdljla/error',
'/index.html'
];
//pre fetch all resources
const promises =
paginatedResources
.map(
url =>
//toResult causes any promise to resolve in a result
result.toResult(//max2(fetch)(url) gets uncaught in promise
max2(//maximal 2 active request (can change throttle)
fetch
)(url)
)
)
;
while(++i<promises.length){
yield promises[i];
}
}
//consuming the itirator
const it = test();
const consumeNext = () =>{
var v;
return (v = it.next()).done
?Promise.resolve("we are done")
//toPromise causes result type to convert in promise
// that is resolved or rejected based on result
// being Value or Error
:result.toPromise(v.value).then(x=>x.text())
}
consumeNext()
.then(
x=>console.log("first resouce:",x.length)
,reject=>console.warn(reject)
)
;
consumeNext()
.then(
x=>console.log("second resouce:",x.length)
,reject=>console.warn(reject)
)
;
consumeNext()
.then(
x=>console.log("third resouce:",x.length)
,reject=>console.warn(reject)
)
;
我也提到了下面的链接,我找不到答案。